cmake_minimum_required(VERSION 3.10)
project(UEStudio)

# 强制要求 MSVC 编译器
if(NOT MSVC)
    message(FATAL_ERROR "This project requires Microsoft Visual C++ compiler. Current compiler: ${CMAKE_CXX_COMPILER_ID}")
endif()

# 检查 MSVC 版本，建议使用 VC++2010 (MSVC 16.0) 或兼容版本
if(MSVC_VERSION LESS 1600)
    message(WARNING "This project is tested with VC++2010 (MSVC 16.0). Current version: ${MSVC_VERSION}")
endif()

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 设置 wxWidgets 路径
set(WXWIN "D:/vc/wxWidgets-3.2.6")
set(WXCFG "vc_lib")
set(wxWidgets_ROOT_DIR "${WXWIN}")
set(wxWidgets_LIB_DIR "${wxWidgets_ROOT_DIR}/lib/${WXCFG}")
set(wxWidgets_INCLUDE_DIRS "${wxWidgets_ROOT_DIR}/include")

# 查找 setup.h（VC++ 编译的版本）
find_file(WX_SETUP_H setup.h 
    PATHS 
    "${wxWidgets_ROOT_DIR}/lib/${WXCFG}/mswud"
    "${wxWidgets_ROOT_DIR}/lib/${WXCFG}/mswu" 
    "${wxWidgets_ROOT_DIR}/build/msw/vc_lib"
    REQUIRED
)

if(WX_SETUP_H)
    # 添加 setup.h 所在目录到头文件路径
    get_filename_component(WX_SETUP_DIR ${WX_SETUP_H} DIRECTORY)
    include_directories(${WX_SETUP_DIR})
endif()

# 包含头文件
include_directories(
    ${wxWidgets_INCLUDE_DIRS}
    ${WX_SETUP_DIR}
    ${CMAKE_SOURCE_DIR}/src/include
    ${CMAKE_SOURCE_DIR}/src/include/tinyxml
    ${CMAKE_SOURCE_DIR}/src/sdk/wxscintilla/include
    ${CMAKE_SOURCE_DIR}/src/plugins/configmanager_common/include
)

# MSVC 特定的编译标志
if(MSVC)
    add_compile_definitions(_UNICODE UNICODE _CRT_SECURE_NO_WARNINGS WXUSINGDLL=0)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /MP")
endif()

# 源文件
file(GLOB_RECURSE SRC_FILES 
    "src/src/*.cpp"
    "src/sdk/*.cpp"
)

add_executable(uestudio WIN32 ${SRC_FILES})

# 链接静态库
target_link_libraries(uestudio
    "${wxWidgets_LIB_DIR}/wxmsw32ud_core.lib"
    "${wxWidgets_LIB_DIR}/wxmsw32ud_stc.lib"
    "${wxWidgets_LIB_DIR}/wxmsw32ud_aui.lib"
    "${wxWidgets_LIB_DIR}/wxmsw32ud_adv.lib"
    "${wxWidgets_LIB_DIR}/wxmsw32ud_html.lib"
    "${wxWidgets_LIB_DIR}/wxmsw32ud_xrc.lib"
    "${wxWidgets_LIB_DIR}/wxmsw32ud_richtext.lib"
    "${wxWidgets_LIB_DIR}/wxbase32ud.lib"
    "${wxWidgets_LIB_DIR}/wxbase32ud_xml.lib"
    "${wxWidgets_LIB_DIR}/wxexpatd.lib"
    "${wxWidgets_LIB_DIR}/wxpngd.lib"
    "${wxWidgets_LIB_DIR}/wxjpegd.lib"
    "${wxWidgets_LIB_DIR}/wxtiffd.lib"
    "${wxWidgets_LIB_DIR}/wxzlibd.lib"
    "${wxWidgets_LIB_DIR}/wxregexud.lib"
)

# Windows 系统库
target_link_libraries(uestudio
    kernel32 user32 gdi32 comdlg32 winspool32
    winmm shell32 comctl32 ole32 oleaut32
    uuid rpcrt4 advapi32 wsock32
)